package com.kzf.controller;

import com.kzf.anno.Log;
import com.kzf.pojo.*;
import com.kzf.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/clazzs")
public class ClassController {

    @Autowired
    public ClassService classService;
    @GetMapping
    public Result getList(ClassQueryParam classQueryParam) {
        log.info("classQueryParam:{}", classQueryParam);
        ClassResult<ClazzDTO> classResult = classService.getList(classQueryParam);
        return Result.success(classResult);
    }

    @Log
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("id:{}", id);
        classService.delete(id);
        return Result.success();
    }

    @Log
    @PostMapping
    public Result insert(@RequestBody Clazz clazz){
        log.info("clazz:{}", clazz);
        classService.insert(clazz);
        return Result.success();
    }

    @Log
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        classService.update(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result getAll(){
        List<ClassById> list = classService.getAll();
        return Result.success(list);
    }

    @GetMapping("{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("id:{}", id);
        ClassById classById = classService.getById(id);
        return Result.success(classById);
    }
}
